USE [mibus]
GO
/****** Object:  ForeignKey [fk_waypoints_ayuda_ruta]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_waypoints_ayuda_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[waypoints_ayuda]'))
ALTER TABLE [dbo].[waypoints_ayuda] DROP CONSTRAINT [fk_waypoints_ayuda_ruta]
GO
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_reserva_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[reservas]'))
ALTER TABLE [dbo].[reservas]  DROP CONSTRAINT [fk_reserva_recorrido_realizado] 
GO
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_historico]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorrido_realizado_historico]'))
ALTER TABLE [dbo].[recorrido_realizado_historico]  DROP CONSTRAINT [fk_recorrido_realizado_historico] 
GO
/****** Object:  ForeignKey [fk_administrador_usuario]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_administrador_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[usuarios_administradores]'))
ALTER TABLE [dbo].[usuarios_administradores] DROP CONSTRAINT [fk_administrador_usuario]
GO
/****** Object:  ForeignKey [fk_parada_ruta]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[rutas_paradas]'))
ALTER TABLE [dbo].[rutas_paradas] DROP CONSTRAINT [fk_parada_ruta]
GO
/****** Object:  ForeignKey [fk_ruta_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_ruta_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[rutas_paradas]'))
ALTER TABLE [dbo].[rutas_paradas] DROP CONSTRAINT [fk_ruta_parada]
GO
/****** Object:  ForeignKey [fk_recorrido_horario]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_horario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos] DROP CONSTRAINT [fk_recorrido_horario]
GO
/****** Object:  ForeignKey [fk_recorrido_ruta]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos] DROP CONSTRAINT [fk_recorrido_ruta]
GO
/****** Object:  ForeignKey [FK_recorrido_realizado_bus]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_recorrido_bus]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos] DROP CONSTRAINT [FK_recorrido_bus]
GO
/****** Object:  ForeignKey [FK_recorrido_realizado_bus]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_recorrido_realizado_bus]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] DROP CONSTRAINT [FK_recorrido_realizado_bus]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_conductor]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_conductor]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] DROP CONSTRAINT [fk_recorrido_realizado_conductor]
GO
/****** Object:  ForeignKey [fk_recorridos_realizados_recorrido]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorridos_realizados_recorrido]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] DROP CONSTRAINT [fk_recorridos_realizados_recorrido]
GO
/****** Object:  ForeignKey [fk_recorridos_realizados_proxima_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorridos_realizados_proxima_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] DROP CONSTRAINT [fk_recorridos_realizados_proxima_parada]
GO
/****** Object:  ForeignKey [fk_parada_recorrido_realizado]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_paradas] DROP CONSTRAINT [fk_parada_recorrido_realizado]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_paradas] DROP CONSTRAINT [fk_recorrido_realizado_parada]
GO
/****** Object:  ForeignKey [fk_evento_recorrido_realizado]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_evento_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]'))
ALTER TABLE [dbo].[recorridos_realizados_eventos] DROP CONSTRAINT [fk_evento_recorrido_realizado]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_evento]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_evento]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]'))
ALTER TABLE [dbo].[recorridos_realizados_eventos] DROP CONSTRAINT [fk_recorrido_realizado_evento]
GO
/****** Object:  ForeignKey [fk_parada_recorrido_realizado_usuario]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_recorrido_realizado_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas] DROP CONSTRAINT [fk_parada_recorrido_realizado_usuario]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_usuario]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas] DROP CONSTRAINT [fk_recorrido_realizado_usuario]
GO
/****** Object:  ForeignKey [fk_usuario_recorrido_realizado]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_usuario_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas] DROP CONSTRAINT [fk_usuario_recorrido_realizado]
GO
/****** Object:  ForeignKey [fk_reservas_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_reservas_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[reservas]'))
ALTER TABLE [dbo].[reservas] DROP CONSTRAINT [fk_reservas_parada]
GO
/****** Object:  Table [dbo].[waypoints_ayuda]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[waypoints_ayuda]') AND type in (N'U'))
DROP TABLE [dbo].[waypoints_ayuda]
GO
/****** Object:  Table [dbo].[recorridos_realizados_usuarios_paradas]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]') AND type in (N'U'))
DROP TABLE [dbo].[recorridos_realizados_usuarios_paradas]
GO
/****** Object:  Table [dbo].[recorridos_realizados_eventos]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]') AND type in (N'U'))
DROP TABLE [dbo].[recorridos_realizados_eventos]
GO
/****** Object:  Table [dbo].[recorridos_realizados_paradas]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]') AND type in (N'U'))
DROP TABLE [dbo].[recorridos_realizados_paradas]
GO
/****** Object:  Table [dbo].[recorridos_realizados]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]') AND type in (N'U'))
DROP TABLE [dbo].[recorridos_realizados]
GO
/****** Object:  Table [dbo].[recorridos]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos]') AND type in (N'U'))
DROP TABLE [dbo].[recorridos]
GO
/****** Object:  Table [dbo].[rutas_paradas]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rutas_paradas]') AND type in (N'U'))
DROP TABLE [dbo].[rutas_paradas]
GO
/****** Object:  Table [dbo].[sesiones]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sesiones]') AND type in (N'U'))
DROP TABLE [dbo].[sesiones]
GO
/****** Object:  Table [dbo].[usuarios_administradores]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usuarios_administradores]') AND type in (N'U'))
DROP TABLE [dbo].[usuarios_administradores]
GO
/****** Object:  Table [dbo].[usuarios]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usuarios]') AND type in (N'U'))
DROP TABLE [dbo].[usuarios]
GO
/****** Object:  Table [dbo].[rutas]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rutas]') AND type in (N'U'))
DROP TABLE [dbo].[rutas]
GO
/****** Object:  Table [dbo].[buses]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[buses]') AND type in (N'U'))
DROP TABLE [dbo].[buses]
GO
/****** Object:  Table [dbo].[conductores]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[conductores]') AND type in (N'U'))
DROP TABLE [dbo].[conductores]
GO
/****** Object:  Table [dbo].[eventos]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[eventos]') AND type in (N'U'))
DROP TABLE [dbo].[eventos]
GO
/****** Object:  Table [dbo].[horarios]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[horarios]') AND type in (N'U'))
DROP TABLE [dbo].[horarios]
GO
/****** Object:  Table [dbo].[paradas]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paradas]') AND type in (N'U'))
DROP TABLE [dbo].[paradas]
GO
/****** Object:  Table [dbo].[reservas]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reservas]') AND type in (N'U'))
DROP TABLE [dbo].[reservas]
GO
/****** Object:  Table [dbo].[transacciones]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[transacciones]') AND type in (N'U'))
DROP TABLE [dbo].[transacciones]
GO
/****** Object:  Table [dbo].[saldos]    Script Date: 07/31/2013 11:59:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[saldos]') AND type in (N'U'))
DROP TABLE [dbo].[saldos]
GO
/****** Object:  Table [dbo].[paradas]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paradas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[paradas](
	[id_parada] [int] IDENTITY(1,1) NOT NULL,
	[nombre_parada] [varchar](30) NOT NULL,
	[direccion_parada] [varchar](50) NOT NULL,
	[latitud] [float] NOT NULL,
	[longitud] [float] NOT NULL,
	[estado_parada] [varchar](20) NOT NULL,
	[fecha_creacion_parada] [datetime] NOT NULL,
	[fecha_modificacion_parada] [datetime] NOT NULL,
 CONSTRAINT [PK_paradas] PRIMARY KEY CLUSTERED 
(
	[id_parada] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[horarios]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[horarios]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[horarios](
	[id_horario] [int] IDENTITY(1,1) NOT NULL,
	[nombre_horario] [varchar](30) NOT NULL,
	[dias_aplica] [varchar](20) NOT NULL,
	[hora_salida] [time](0) NOT NULL,
	[hora_estimada_llegada] [time](0) NOT NULL,
	[estado_horario] [varchar](20) NOT NULL,
	[fecha_creacion_horario] [datetime] NOT NULL,
	[fecha_modificacion_horario] [datetime] NOT NULL,
 CONSTRAINT [PK_horarios] PRIMARY KEY CLUSTERED 
(
	[id_horario] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[eventos]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[eventos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[eventos](
	[id_evento] [int] IDENTITY(1,1) NOT NULL,
	[nombre_evento] [varchar](30) NOT NULL,
	[descripcion_evento] [varchar](70) NOT NULL,
	[fecha_creacion_evento] [datetime] NOT NULL,
	[fecha_modificacion_evento] [datetime] NOT NULL,
 CONSTRAINT [PK_eventos] PRIMARY KEY CLUSTERED 
(
	[id_evento] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[conductores]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[conductores]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[conductores](
	[id_conductor] [int] IDENTITY(1,1) NOT NULL,
	[nombre_conductor] [varchar](30) NOT NULL,
	[identificacion_conductor] [varchar](30) NOT NULL,
	[estado_conductor] [varchar](20) NOT NULL,
	[fecha_creacion_conductor] [datetime] NOT NULL,
	[fecha_modificacion_conductor] [datetime] NOT NULL,
	[usuario_conductor] [varchar](30) NOT NULL,
	[clave_conductor] [varchar](32) NOT NULL,
	[fecha_ultima_sesion_conductor] [datetime] NULL,
	[hash_sesion_conductor] [varchar](32) NULL,
 CONSTRAINT [PK_conductor] PRIMARY KEY CLUSTERED 
(
	[id_conductor] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[buses]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[buses]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[buses](
	[id_bus] [int] IDENTITY(1,1) NOT NULL,
	[placa] [varchar](10) NOT NULL,
	[capacidad] [int] NOT NULL,
	[empresa] [varchar](50) NOT NULL,
	[estado_bus] [varchar](20) NOT NULL,
	[fecha_creacion_bus] [datetime] NOT NULL,
	[fecha_modificacion_bus] [datetime] NOT NULL,
 CONSTRAINT [PK_Buses] PRIMARY KEY CLUSTERED 
(
	[id_bus] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[rutas]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rutas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[rutas](
	[id_ruta] [int] IDENTITY(1,1) NOT NULL,
	[nombre_ruta] [varchar](30) NOT NULL,
	[descripcion_ruta] [varchar](70) NOT NULL,
	[estado_ruta] [varchar](20) NOT NULL,
	[fecha_creacion_ruta] [datetime] NOT NULL,
	[fecha_modificacion_ruta] [datetime] NOT NULL,
 CONSTRAINT [PK_rutas] PRIMARY KEY CLUSTERED 
(
	[id_ruta] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[usuarios]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usuarios]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[usuarios](
	[id_usuario] [int] IDENTITY(1,1) NOT NULL,
	[nombre_usuario] [varchar](50) NOT NULL,
	[identificacion_usuario] [varchar](30) NOT NULL,
	[telefono] [varchar](55) NULL,
	[correo] [varchar](50) NOT NULL,
	[celular] [varchar](30) NOT NULL,
	[fecha_creacion_usuario] [datetime] NOT NULL,
	[fecha_modificacion_usuario] [datetime] NOT NULL
 CONSTRAINT [PK_usuarios] PRIMARY KEY CLUSTERED 
(
	[id_usuario] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[usuarios_administradores]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usuarios_administradores]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[usuarios_administradores](
	[id_usuario_administrador] [int] IDENTITY(1,1) NOT NULL,
	[id_usuario] [varchar](15) NOT NULL,
	[fecha_creacion_administrador] [datetime] NOT NULL,
	[fecha_ultimo_inicio_sesion] [datetime] NULL,
	[fecha_modificacion_administrador] [datetime] NOT NULL,
 CONSTRAINT [PK_usuarios_administradores] PRIMARY KEY CLUSTERED 
(
	[id_usuario_administrador] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[sesiones]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sesiones]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[sesiones](
	[id_sesion] [int] IDENTITY(1,1) NOT NULL,
	[id_usuario] [varchar](15) NOT NULL,
	[fecha_inicio_sesion] [datetime] NOT NULL,
	[fecha_fin_sesion] [datetime] NULL,
 CONSTRAINT [PK_sesiones] PRIMARY KEY CLUSTERED 
(
	[id_sesion] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[rutas_paradas]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rutas_paradas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[rutas_paradas](
	[id_rutas_paradas] [int] IDENTITY(1,1) NOT NULL,
	[id_ruta] [int] NOT NULL,
	[id_parada] [int] NOT NULL,
	[orden_ruta] [int] NOT NULL,
	[tipo_parada] [varchar](10) NOT NULL,
 CONSTRAINT [PK_rutas_paradas] PRIMARY KEY CLUSTERED 
(
	[id_rutas_paradas] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[recorridos]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[recorridos](
	[id_recorrido] [int] IDENTITY(1,1) NOT NULL,
	[estado_recorrido] [varchar](20) NOT NULL,
	[fecha_creacion_recorrido] [datetime] NOT NULL,
	[fecha_modificacion_recorrido] [datetime] NOT NULL,
	[id_ruta] [int] NOT NULL,
	[id_horario] [int] NOT NULL,
	[id_bus] [int] NOT NULL,
 CONSTRAINT [PK_recorridos] PRIMARY KEY CLUSTERED 
(
	[id_recorrido] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[recorridos_realizados]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[recorridos_realizados](
	[id_recorrido_realizado] [int] IDENTITY(1,1) NOT NULL,
	[fecha_salida] [datetime] NULL,
	[fecha_llegada] [datetime] NULL,
	[estado_recorrido_realizado] [varchar](20) NOT NULL,
	[id_bus] [int] NULL,
	[id_conductor] [int] NULL,
	[id_recorrido] [int] NOT NULL,
	[latitud] [real] NOT NULL,
	[longitud] [real] NOT NULL,
	[velocidad_promedio] [real] NOT NULL,
	[puestos_ocupados] [int] NOT NULL,
	[puestos_reservados] [int] NOT NULL,
	[id_proxima_parada] [int] NULL,
	[contador_inactividad] [int] NULL,
	[fecha_actualizacion_recorrido] [datetime] NULL,
 CONSTRAINT [PK_recorridos_realizados] PRIMARY KEY CLUSTERED 
(
	[id_recorrido_realizado] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[recorridos_realizados_paradas]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[recorridos_realizados_paradas](
	[id_recorridos_realizados_paradas] [int] IDENTITY(1,1) NOT NULL,
	[id_recorrido_realizado] [int] NOT NULL,
	[id_parada] [int] NOT NULL,
	[hora_llegada_parada] [time](0) NOT NULL,
	[hora_salida_parada] [time](0) NULL,
 CONSTRAINT [PK_recorridos_realizados_paradas] PRIMARY KEY CLUSTERED 
(
	[id_recorridos_realizados_paradas] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[recorridos_realizados_eventos]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[recorridos_realizados_eventos](
	[id_recorrido_realizado_evento] [int] IDENTITY(1,1) NOT NULL,
	[id_recorrido_realizado] [int] NOT NULL,
	[id_evento] [int] NOT NULL,
	[fecha_hora_evento] [datetime] NOT NULL,
	[latitud] [real] NOT NULL,
	[longitud] [real] NOT NULL
 CONSTRAINT [PK_recorridos_realizados_eventos] PRIMARY KEY CLUSTERED 
(
	[id_recorrido_realizado_evento] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[recorridos_realizados_usuarios_paradas]    Script Date: 07/31/2013 11:59:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[recorridos_realizados_usuarios_paradas](
	[id_recorridos_realizados_usuarios_paradas] [int] IDENTITY(1,1) NOT NULL,
	[id_recorridos_realizados_paradas] [int] NOT NULL,
	[id_usuario] [varchar](15) NOT NULL,
	[tipo_movimiento] [varchar](10) NOT NULL,
	[id_recorrido_realizado] [int] NOT NULL,
 CONSTRAINT [PK_recorridos_realizados_usuarios_paradas] PRIMARY KEY CLUSTERED 
(
	[id_recorridos_realizados_usuarios_paradas] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[reservas]    Script Date: 09/27/2013 11:14:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reservas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[reservas](
	[id_reserva] [int] IDENTITY(1,1) NOT NULL,
	[id_usuario] [varchar](15) NOT NULL,
	[id_recorrido_realizado] [int] NOT NULL,
	[fecha_creacion_reserva] [datetime] NOT NULL,
	[fecha_modificacion_reserva] [datetime] NOT NULL,
	[estado_reserva] [varchar](20) NOT NULL,
	[id_parada] [int] NOT NULL,
 CONSTRAINT [PK_reservas] PRIMARY KEY CLUSTERED 
(
	[id_reserva] ASC,
	[id_usuario] ASC,
	[id_recorrido_realizado] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[transacciones]    Script Date: 09/27/2013 11:14:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[transacciones]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[transacciones](
	[id_transaccion] [int] IDENTITY(1,1) NOT NULL,
	[id_usuario] [varchar](15) NOT NULL,
	[monto] [real] NOT NULL,
	[tipo_transaccion] [varchar](10) NOT NULL,
	[fecha_creacion_transaccion] [datetime] NOT NULL,
 CONSTRAINT [PK_transacciones] PRIMARY KEY CLUSTERED 
(
	[id_transaccion] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[saldos]    Script Date: 09/27/2013 11:14:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[saldos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[saldos](
	[id_saldo] [int] IDENTITY(1,1) NOT NULL,
	[id_usuario] [varchar](15) NOT NULL,
	[monto] [real] NOT NULL,
	[fecha_creacion_saldo] [datetime] NOT NULL,
	[fecha_modificacion_saldo] [datetime] NOT NULL,
 CONSTRAINT [PK_saldos] PRIMARY KEY CLUSTERED 
(
	[id_saldo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[waypoints_ayuda]    Script Date: 10/20/2013 22:14:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[waypoints_ayuda]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[waypoints_ayuda](
	[id_waypoint_ayuda] [int] IDENTITY(1,1) NOT NULL,
	[id_ruta] [int] NOT NULL,
	[id_waypoint_parada] [int] NOT NULL,
	[latitud] [numeric](20,17) NOT NULL,
	[longitud] [numeric](20,17) NOT NULL,
 CONSTRAINT [PK_waypoints_ayuda] PRIMARY KEY CLUSTERED 
(
	[id_waypoint_ayuda] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[recorrido_realizado_historico]    Script Date: 10/20/2013 22:14:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[recorrido_realizado_historico]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[recorrido_realizado_historico](
	[id_recorrido_realizado_historico] [int] IDENTITY(1,1) NOT NULL,
	[id_recorrido_realizado] [int] NOT NULL,
	[fecha_hora_guardado_servidor] [datetime] NOT NULL,
	[fecha_hora_solicitud_gps] [datetime] NULL,
	[fecha_hora_envio_servidor] [datetime] NULL,
	[latitud] [numeric](20,17) NOT NULL,
	[longitud] [numeric](20,17) NOT NULL,
	[velocidad] [real] NULL
 CONSTRAINT [PK_recorrido_realizado_historico] PRIMARY KEY CLUSTERED 
(
	[id_recorrido_realizado_historico]
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_administrador_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[usuarios_administradores]'))
ALTER TABLE [dbo].[usuarios_administradores] CHECK CONSTRAINT [fk_administrador_usuario]
GO
/****** Object:  ForeignKey [fk_parada_ruta]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[rutas_paradas]'))
ALTER TABLE [dbo].[rutas_paradas]  WITH CHECK ADD  CONSTRAINT [fk_parada_ruta] FOREIGN KEY([id_parada])
REFERENCES [dbo].[paradas] ([id_parada])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[rutas_paradas]'))
ALTER TABLE [dbo].[rutas_paradas] CHECK CONSTRAINT [fk_parada_ruta]
GO
/****** Object:  ForeignKey [fk_ruta_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_ruta_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[rutas_paradas]'))
ALTER TABLE [dbo].[rutas_paradas]  WITH CHECK ADD  CONSTRAINT [fk_ruta_parada] FOREIGN KEY([id_ruta])
REFERENCES [dbo].[rutas] ([id_ruta])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_ruta_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[rutas_paradas]'))
ALTER TABLE [dbo].[rutas_paradas] CHECK CONSTRAINT [fk_ruta_parada]
GO
/****** Object:  ForeignKey [fk_recorrido_horario]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_horario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_horario] FOREIGN KEY([id_horario])
REFERENCES [dbo].[horarios] ([id_horario])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_horario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos] CHECK CONSTRAINT [fk_recorrido_horario]
GO
/****** Object:  ForeignKey [fk_recorrido_ruta]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_ruta] FOREIGN KEY([id_ruta])
REFERENCES [dbo].[rutas] ([id_ruta])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos] CHECK CONSTRAINT [fk_recorrido_ruta]
GO
/****** Object:  ForeignKey [FK_recorrido_bus]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_recorrido_bus]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos]'))
ALTER TABLE [dbo].[recorridos]  WITH CHECK ADD  CONSTRAINT [FK_recorrido_bus] FOREIGN KEY([id_bus])
REFERENCES [dbo].[buses] ([id_bus])
GO
/****** Object:  ForeignKey [FK_recorrido_realizado_bus]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_recorrido_realizado_bus]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados]  WITH CHECK ADD  CONSTRAINT [FK_recorrido_realizado_bus] FOREIGN KEY([id_bus])
REFERENCES [dbo].[buses] ([id_bus])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_recorrido_realizado_bus]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] CHECK CONSTRAINT [FK_recorrido_realizado_bus]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_conductor]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_conductor]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_realizado_conductor] FOREIGN KEY([id_conductor])
REFERENCES [dbo].[conductores] ([id_conductor])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_conductor]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] CHECK CONSTRAINT [fk_recorrido_realizado_conductor]
GO
/****** Object:  ForeignKey [fk_recorridos_realizados_recorrido]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorridos_realizados_recorrido]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados]  WITH CHECK ADD  CONSTRAINT [fk_recorridos_realizados_recorrido] FOREIGN KEY([id_recorrido])
REFERENCES [dbo].[recorridos] ([id_recorrido])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorridos_realizados_recorrido]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] CHECK CONSTRAINT [fk_recorridos_realizados_recorrido]
GO
/****** Object:  ForeignKey [fk_recorridos_realizados_proxima_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorridos_realizados_proxima_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados]  WITH CHECK ADD  CONSTRAINT [fk_recorridos_realizados_proxima_parada] FOREIGN KEY([id_proxima_parada])
REFERENCES [dbo].[paradas] ([id_parada])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorridos_realizados_proxima_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados]'))
ALTER TABLE [dbo].[recorridos_realizados] CHECK CONSTRAINT [fk_recorridos_realizados_proxima_parada]
GO
/****** Object:  ForeignKey [fk_parada_recorrido_realizado]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_paradas]  WITH CHECK ADD  CONSTRAINT [fk_parada_recorrido_realizado] FOREIGN KEY([id_parada])
REFERENCES [dbo].[paradas] ([id_parada])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_paradas] CHECK CONSTRAINT [fk_parada_recorrido_realizado]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_parada]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_paradas]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_realizado_parada] FOREIGN KEY([id_recorrido_realizado])
REFERENCES [dbo].[recorridos_realizados] ([id_recorrido_realizado])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_paradas] CHECK CONSTRAINT [fk_recorrido_realizado_parada]
GO
/****** Object:  ForeignKey [fk_evento_recorrido_realizado]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_evento_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]'))
ALTER TABLE [dbo].[recorridos_realizados_eventos]  WITH CHECK ADD  CONSTRAINT [fk_evento_recorrido_realizado] FOREIGN KEY([id_evento])
REFERENCES [dbo].[eventos] ([id_evento])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_evento_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]'))
ALTER TABLE [dbo].[recorridos_realizados_eventos] CHECK CONSTRAINT [fk_evento_recorrido_realizado]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_evento]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_evento]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]'))
ALTER TABLE [dbo].[recorridos_realizados_eventos]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_realizado_evento] FOREIGN KEY([id_recorrido_realizado])
REFERENCES [dbo].[recorridos_realizados] ([id_recorrido_realizado])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_evento]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_eventos]'))
ALTER TABLE [dbo].[recorridos_realizados_eventos] CHECK CONSTRAINT [fk_recorrido_realizado_evento]
GO
/****** Object:  ForeignKey [fk_parada_recorrido_realizado_usuario]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_recorrido_realizado_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas]  WITH CHECK ADD  CONSTRAINT [fk_parada_recorrido_realizado_usuario] FOREIGN KEY([id_recorridos_realizados_paradas])
REFERENCES [dbo].[recorridos_realizados_paradas] ([id_recorridos_realizados_paradas])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_parada_recorrido_realizado_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas] CHECK CONSTRAINT [fk_parada_recorrido_realizado_usuario]
GO
/****** Object:  ForeignKey [fk_recorrido_realizado_usuario]    Script Date: 07/31/2013 11:59:34 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_realizado_usuario] FOREIGN KEY([id_recorrido_realizado])
REFERENCES [dbo].[recorridos_realizados] ([id_recorrido_realizado])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas] CHECK CONSTRAINT [fk_recorrido_realizado_usuario]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_usuario_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorridos_realizados_usuarios_paradas]'))
ALTER TABLE [dbo].[recorridos_realizados_usuarios_paradas] CHECK CONSTRAINT [fk_usuario_recorrido_realizado]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_reserva_recorrido_realizado]') AND parent_object_id = OBJECT_ID(N'[dbo].[reservas]'))
ALTER TABLE [dbo].[reservas]  WITH CHECK ADD  CONSTRAINT [fk_reserva_recorrido_realizado] FOREIGN KEY([id_recorrido_realizado])
REFERENCES [dbo].[recorridos_realizados] ([id_recorrido_realizado])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_recorrido_realizado_historico]') AND parent_object_id = OBJECT_ID(N'[dbo].[recorrido_realizado_historico]'))
ALTER TABLE [dbo].[recorrido_realizado_historico]  WITH CHECK ADD  CONSTRAINT [fk_recorrido_realizado_historico] FOREIGN KEY([id_recorrido_realizado])
REFERENCES [dbo].[recorridos_realizados] ([id_recorrido_realizado])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_waypoints_ayuda_ruta]') AND parent_object_id = OBJECT_ID(N'[dbo].[waypoints_ayuda]'))
ALTER TABLE [dbo].[waypoints_ayuda]  WITH CHECK ADD  CONSTRAINT [fk_waypoints_ayuda_ruta] FOREIGN KEY([id_ruta])
REFERENCES [dbo].[rutas] ([id_ruta])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_reservas_parada]') AND parent_object_id = OBJECT_ID(N'[dbo].[reservas]'))
ALTER TABLE [dbo].[reservas]  WITH CHECK ADD  CONSTRAINT [fk_reservas_parada] FOREIGN KEY([id_parada])
REFERENCES [dbo].[paradas] ([id_parada])
GO